﻿<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
	<meta charset="utf-8" />
    <link rel="stylesheet" href="plugins/layui/css/layui.css" media="all" />
    <script src="js/jquery-3.1.1.min.js"></script>
    <script src="js/uuid.js"></script>
</head>
<body>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-inline">
                <input type="text" name="username" lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input" value="admin">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <input type="password" name="password" lay-verify="pass" placeholder="请输入密码" autocomplete="off" class="layui-input" value="administrator">
            </div>
            <div class="layui-form-mid layui-word-aux">请填写6到12位密码</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认</label>
            <div class="layui-input-inline">
                <input type="password" name="" lay-verify="" placeholder="请再输入密码" autocomplete="off" class="layui-input" value="administrator">
            </div>
            <div class="layui-form-mid layui-word-aux">确认密码</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-inline">
                <input type="text" name="email" lay-verify="email" placeholder="admin@admin.com" autocomplete="off" class="layui-input" value="admin@admin.com">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" id="publish" lay-submit="" lay-filter="tijiao">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
        </form>
        <script type="text/javascript" src="plugins/layui/layui.js"></script>
        <script src="ajax/main.js"></script>
        <script>
            layui.use(['form'], function () {
                var form = layui.form(),
					layer = layui.layer;

                //自定义验证规则
                form.verify({
                    title: function (value) {
                        if (value.length < 5) {
                            return '标题至少得5个字符啊';
                        }
                    },
                    pass: [/(.+){6,12}$/, '密码必须6到12位'],
                    content: function (value) {
                        layedit.sync(editIndex);
                    }
                });
                
                //监听提交
                form.on('submit(tijiao)', function (data) {
                    var v = null;
                    $.each(data.field, function (index, objVal) {
                        v == null ? v = "'" + objVal + "'" : v = v + ',' + "'" + objVal + "'";
                    });
                    var field_id = new Array("id", "user_name", "user_pwd", "user_email", "authority");
                    var value = "'" + uuid(8, 16) + "'," + v  + ",'admin'";
                    CJPlugin.execute("admin", value, "insert", "ExecuteHandler",field_id);

                    //layer.alert(JSON.stringify(data.field), {
                    //    title: '最终的提交信息'
                    //})
                    return false;
                });
            });
        </script>
</body>
</html>
